var testCase_left = {
		//左侧分类下拉框触发
		typeChange : function(){
			
			var type = $('#type option:selected').val();
			chooseType = type;
			moduleId = "";
			assignId = "";
			authorId = "";
			testCase_left.listTreeOnTestCase(type);
			testCase_left.initZtree();
			var params={
		            silent: true,
		            url:path+"/testCaseController/listTestCase?chooseType="+chooseType
					+"&&nodeId="+nodeId+"&&showAll="+showAll+"&&moduleId="+moduleId+"&&assignId="+assignId+"&&authorId="+authorId
		    };
			$('#testCaseTable').bootstrapTable('refresh',params);
			testCase_list.listQueryParams();
		},
		initZtree : function(){
			$.fn.zTree.init($("#treeDemo"), setting, zNodes);
			$("#expandAllBtn").bind("click", {type:"expandAll"}, testCase_left.expandNode);
			$("#collapseAllBtn").bind("click", {type:"collapseAll"}, testCase_left.expandNode);
			
			var zTree = $.fn.zTree.getZTreeObj("treeDemo");
			zTree.expandAll(true);
			var nodes = zTree.getNodes();
			if(nodes[0].children){
				zTree.selectNode(nodes[0].children[0]);
				nodeId = nodes[0].children[0].id;
			}else{
				zTree.selectNode(nodes[0]);
				nodeId = nodes[0].id;
			}
		},
		zTreeOnClick : function(event, treeId, treeNode){
			nodeId = treeNode.id;
			moduleId = "";
			assignId = "";
			authorId = "";
			var params={
		            silent: true,
		            url:path+"/testCaseController/listTestCase?chooseType="+chooseType
					+"&&nodeId="+nodeId+"&&showAll="+showAll+"&&moduleId="+moduleId+"&&assignId="+assignId+"&&authorId="+authorId
		    };
			$('#testCaseTable').bootstrapTable('refresh',params);
			testCase_list.listQueryParams();
		},
		expandNode : function(e){
			var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
			type = e.data.type,
			nodes = zTree.getSelectedNodes();
			if (type.indexOf("All")<0 && nodes.length == 0) {
				alert("请先选择一个父节点");
			}

			if (type == "expandAll") {
				zTree.expandAll(true);
			} else if (type == "collapseAll") {
				zTree.expandAll(false);
			} else {
				var callbackFlag = $("#callbackTrigger").attr("checked");
				for (var i=0, l=nodes.length; i<l; i++) {
					zTree.setting.view.fontCss = {};
					if (type == "expand") {
						zTree.testCase_left.expandNode(nodes[i], true, null, null, callbackFlag);
					} else if (type == "collapse") {
						zTree.testCase_left.expandNode(nodes[i], false, null, null, callbackFlag);
					} else if (type == "toggle") {
						zTree.testCase_left.expandNode(nodes[i], null, null, null, callbackFlag);
					} else if (type == "expandSon") {
						zTree.testCase_left.expandNode(nodes[i], true, true, null, callbackFlag);
					} else if (type == "collapseSon") {
						zTree.testCase_left.expandNode(nodes[i], false, true, null, callbackFlag);
					}
				}
			}
			
		},
		listTreeOnTestCase : function(type){
			$.ajax({
			    type : "get",
			    async: false,//必须同步
			    url : path+'/testCaseController/listTreeOnTestCase?type='+type,//找到controller里相应的方法
			    beforeSend: function(XMLHttpRequest){
			    	
	        	},
			    success : function(dataList) {
			    	zNodes = [];
			    	$(dataList).each(function(index,data){
			    		zNodes.push({ id:data.id, pId:data.parentId, name:data.name});
			    		
			    	});
			    	
			    },
			    complete: function(XMLHttpRequest, textStatus){
			    	
			    	
	        	}
			   });
			
			
		}

		
};

var testCase_list = {
		deleteTestCase : function(index){
//			debugger;
			setTimeout(function() {
				$(".fixed-table-container tbody tr[data-index='"+index+"']").addClass("selected");
			}, 50);
			
			layer.confirm('确定要删除该用例吗？', {icon: 3, title:'<span class="glyphicon glyphicon-th-large"></span>&nbsp;提示'}, function(){
				var rowData = $("#testCaseTable").bootstrapTable('getData')[index];
				 var testcaseIds = rowData.testcaseId;
				 
				 $.ajax({
		    	        type : "post",
		    	        url : path+'/testCaseController/deleteTestCase',//找到controller里相应的方法
		    	        data : {"testcaseIds":testcaseIds}, //把数组的值赋给data，把上面的param改为data,这里就能直接去掉
		    	        dataType : "json",//根据数据类型选择text、jason等
		    	        success : function(data) { 
		    	        	if(data.result == true){
		    	        		var params={
			    			            silent: true,
			    			            url:path+"/testCaseController/listTestCase?chooseType="+chooseType
			    						+"&&nodeId="+nodeId+"&&showAll="+showAll+"&&moduleId="+moduleId+"&&assignId="+assignId+"&&authorId="+authorId
			    			    };
			    				$('#testCaseTable').bootstrapTable('refresh',params);
				        		parent.layer.closeAll();
				        		parent.toast.success('操作成功！','成功提示');
				        	}else{
				        		toast.error('操作失败！','失败提示');
				        	}
		    	        }
		    	       });
			});
			 

			 
			 
			 
		},
		listQueryParams : function(){
			$.ajax({
			    type : "get",
			    url : path+"/testCaseController/listQueryParams?chooseType="+chooseType
				+"&&nodeId="+nodeId+"&&showAll="+showAll+"&&moduleId="+moduleId+"&&assignId="+assignId+"&&authorId="+authorId,//找到controller里相应的方法
			    beforeSend: function(XMLHttpRequest){
			    	
	        	},
			    success : function(dataMap) {
			    	//模块列表
			    	var moduleList = dataMap.module;
			    	$("#moduleId").html("<option value=''>全部</option>");
    		    	$(moduleList).each(function(index,module){
    		    		$("#moduleId").append("<option value="+module.moduleId+">"+module.moduleNm+"</option>");
    				});
			    	
    		    	//指派人列表
			    	var assignerList = dataMap.assigner;
			    	$("#assigner").html("<option value=''>全部</option>");
    		    	$(assignerList).each(function(index,assigner){
    		    		$("#assigner").append("<option value="+assigner.userId+">"+assigner.userName+"</option>");
    				});	
			    	
			    	//创建人列表
			    	var authorList = dataMap.author;
			    	$("#author").html("<option value=''>全部</option>");
    		    	$(authorList).each(function(index,author){
    		    		$("#author").append("<option value="+author.userId+">"+author.userName+"</option>");
    				});
    		    	
			    },
			    complete: function(XMLHttpRequest, textStatus){
			    	
			    	
	        	}
			   });
			
		},
		moduleChange : function(){
			moduleId = $('#moduleId option:selected').val();
			var params={
		            silent: true,
		            url:path+"/testCaseController/listTestCase?chooseType="+chooseType
					+"&&nodeId="+nodeId+"&&showAll="+showAll+"&&moduleId="+moduleId+"&&assignId="+assignId+"&&authorId="+authorId
		    };
			$('#testCaseTable').bootstrapTable('refresh',params);
		},
		assignerChange : function(){
			assignId = $('#assigner option:selected').val();
			var params={
		            silent: true,
		            url:path+"/testCaseController/listTestCase?chooseType="+chooseType
					+"&&nodeId="+nodeId+"&&showAll="+showAll+"&&moduleId="+moduleId+"&&assignId="+assignId+"&&authorId="+authorId
		    };
			$('#testCaseTable').bootstrapTable('refresh',params);
			
		},
		authorChange : function(){
			
			authorId = $('#author option:selected').val();
			var params={
		            silent: true,
		            url:path+"/testCaseController/listTestCase?chooseType="+chooseType
					+"&&nodeId="+nodeId+"&&showAll="+showAll+"&&moduleId="+moduleId+"&&assignId="+assignId+"&&authorId="+authorId
		    };
			$('#testCaseTable').bootstrapTable('refresh',params);
		},
		resetTable : function(){
			$('#moduleId').val("");
			$('#assigner').val("");
			$('#author').val("");
			moduleId = "";
			assignId = "";
			authorId = "";
			var params={
		            silent: true,
		            url:path+"/testCaseController/listTestCase?chooseType="+chooseType
					+"&&nodeId="+nodeId+"&&showAll="+showAll+"&&moduleId="+moduleId+"&&assignId="+assignId+"&&authorId="+authorId
		    };
			$('#testCaseTable').bootstrapTable('refresh',params);
			
		}
		
};


